package com.banmao.mall.controller.admin;

import com.alibaba.druid.util.StringUtils;
import com.banmao.mall.model.bo.admin.user.*;
import com.banmao.mall.model.vo.BaseRespVO;
import com.banmao.mall.model.vo.admin.user.*;
import com.banmao.mall.service.admin.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class UserController {

    @Autowired
    UserService userService;

    // 获取User会员信息
    @RequestMapping("/user/list")
    @RequiresPermissions("admin:user:list")
    public BaseRespVO userList(UserListBO userListBO) {

        //System.out.println(userListBO);

        // 调用Service
        UserListVO userListVO = userService.userList(userListBO);

        return BaseRespVO.ok(userListVO);
    }


    // 获取用户地址信息
    @RequestMapping("/address/list")
    @RequiresPermissions("admin:address:list")
    public BaseRespVO addressList(AddressListBO addressListBO) {

        // 判断userId的输入值是否为数字
        if(!StringUtils.isEmpty(addressListBO.getUserId())) {
            Integer.parseInt(addressListBO.getUserId());
        }

        AddressListVO addressListVO = userService.addressList(addressListBO);

        return BaseRespVO.ok(addressListVO);
    }


    // 会员收藏
    @RequestMapping("/collect/list")
    @RequiresPermissions("admin:collect:list")
    public BaseRespVO collectList(CollectListBO collectListBO) {

        // 判断userId和valueId是否为数字
        if(!StringUtils.isEmpty(collectListBO.getUserId())) {
            Integer.parseInt(collectListBO.getUserId());
        }
        if(!StringUtils.isEmpty(collectListBO.getValueId())) {
            Integer.parseInt(collectListBO.getValueId());
        }

        CollectListVO collectListVO = userService.collectList(collectListBO);

        return BaseRespVO.ok(collectListVO);
    }


    // 会员足迹
    @RequestMapping("/footprint/list")
    @RequiresPermissions("admin:footprint:list")
    public BaseRespVO footprintList(FootprintListBO footprintListBO) {

        // 判断userId和goodsId是否为数字
        if(!StringUtils.isEmpty(footprintListBO.getUserId())) {
            Integer.parseInt(footprintListBO.getUserId());
        }
        if(!StringUtils.isEmpty(footprintListBO.getGoodsId())) {
            Integer.parseInt(footprintListBO.getGoodsId());
        }

        FootprintListVO footprintListVO = userService.footprintList(footprintListBO);

        return BaseRespVO.ok(footprintListVO);
    }


    // 用户搜索历史
    @RequestMapping("/history/list")
    @RequiresPermissions("admin:history:list")
    public BaseRespVO historyList(HistoryListBO historyListBO) {

        // 判断userId是否为数字
        if(!StringUtils.isEmpty(historyListBO.getUserId())) {
            Integer.parseInt(historyListBO.getUserId());
        }

        HistoryListVO historyListVO = userService.historyList(historyListBO);

        return BaseRespVO.ok(historyListVO);
    }


    // 用户意见反馈
    @RequestMapping("/feedback/list")
    @RequiresPermissions("admin:feedback:list")
    public BaseRespVO feedbackList(FeedbackListBO feedbackListBO) {

        if(!StringUtils.isEmpty(feedbackListBO.getId())) {
            Integer.parseInt(feedbackListBO.getId());
        }

        FeedbackListVO feedbackListVO = userService.feedbackList(feedbackListBO);

        return BaseRespVO.ok(feedbackListVO);
    }
}
